package com.example.foobar.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.foobar.business.service.DidiOrderService;
import com.example.foobar.dao.service.DidiOrdersDaoService;
import com.example.foobar.entity.DidiCompany;
import com.example.foobar.entity.DidiOrders;
import com.example.foobar.param.DidiDateParam;
import com.example.foobar.param.DidiOrdersPageParam;
import com.example.foobar.vo.DidiData;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.text.ParseException;
import java.util.Comparator;
import java.util.Date;

@Slf4j
@Service
public class DidiOrderServiceImpl implements DidiOrderService {


    @Autowired
    private DidiOrdersDaoService didiOrderDaoService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDidiOrders(DidiOrders didiOrders) throws Exception {
        return didiOrderDaoService.save(didiOrders);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDidiOrders(DidiOrders didiOrders) throws Exception {
        return didiOrderDaoService.updateById(didiOrders);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDidiOrders(Long id) throws Exception {
        return didiOrderDaoService.removeById(id);
    }

    @Override
    public Paging<DidiOrders> getDidiOrdersPageList(DidiOrdersPageParam didiOrdersPageParam) throws Exception {
        return didiOrderDaoService.getDidiOrdersPageList(didiOrdersPageParam);
    }

    @Override
    public DidiOrders getById(Long id) throws Exception {
        return didiOrderDaoService.getById(id);
    }

    @Override
    public boolean saveOrUpdateByOrderId(DidiOrders didiOrders) {
        didiOrders.setDate(didiOrders.getPayTime());
        UpdateWrapper wrapper = new UpdateWrapper<DidiOrders>()
                .eq("order_id", didiOrders.getOrderId());
        return didiOrderDaoService.saveOrUpdate(didiOrders, wrapper);
    }

    @Override
    public Paging<DidiData> getDidiDateList(DidiDateParam didiDateParam) {
        Page<DidiData> page = new PageInfo<>(didiDateParam);
        IPage<DidiData> iPage = didiOrderDaoService.getDidiDateList(page, didiDateParam);
        return new Paging<DidiData>(iPage);
    }

}
